package com.exam.controller;

import com.exam.pojo.ExamManage;
import com.exam.service.ExamMenageService;
import com.exam.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamMenageController {

    @Autowired
    private ExamMenageService examMenageService;

    @GetMapping("/{id}")
    public Result find(@PathVariable("id") Integer paperId){
        return new Result(true,examMenageService.findById(paperId));
    }

    @PostMapping
    public Result insert(@RequestBody ExamManage examManage){
        int i = examMenageService.insertById(examManage);
        if(i>0){
            return new Result(true,"增加成功");
        }else{
            return new Result(false,"增加失败");
        }
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer paperId){
        int i = examMenageService.deleteById(paperId);
        if(i>0){
            return new Result(true,"删除成功");
        }else{
            return new Result(false,"删除失败");
        }
    }

    @PutMapping
    public Result update(@RequestBody ExamManage examManage){
        int i = examMenageService.updateById(examManage);
        if(examMenageService.updateById(examManage)>0){
            return new Result(true,"修改成功");
        }else{
            return new Result(false,"修改失败");
        }
    }

    @GetMapping
    public Result findAll(){
        return new Result(true,examMenageService.getExamMangeAll());
    }
}
